<template>
	<view class="warp">
		<view>{{shopName}}</view>
		<view style="width:100%">
			<u-navbar
			    leftText="返回"
			    title="菜品管理"
			    :safeAreaInsetTop="false"
				@leftClick="backPage"
				@rightClick = "addGoods"
			>
			    <view
			        class="u-nav-slot"
			        slot="left"
			    >
			        <u-icon
			            name="arrow-left"
			            size="19"
			        ></u-icon>
			    </view>
				<view
				    class="u-nav-slot"
				    slot="right"
				>
					<u-icon
						name="plus"
						size="20"
					></u-icon>
				</view>
			</u-navbar>
		</view>
		       
		<view class="mdol">
			<block v-for="(data,index) in list" :v-key="index">
			   <view class="shop">
				  <u-row @click="goGoodsDe(data)">
					<u-col span="4" > 
						<image :src="uploadFilePath+data.dimg"  v-if="data.dimg" style="width:100%;height:220rpx" mode="aspectFill"></image>
						<image v-else mode="aspectFill" style="width:100%;height:5rem;"  :src="`${picUrl}goods.png`"></image>
					</u-col>
					<u-col span="6" offset="1">
						<view style="display: flex;">
							<view>{{data.dname}}</view>
							<u-icon v-if="data.iscollect==0" name="heart"  color="#ff0000"/>
							<u-icon v-else name="heart-fill"  color="#ff0000"/>
						</view>
					   <view style="margin:10rpx 0px;">
						 <text class="utag">已售{{data.dishsum}}份</text>
						 <text class="utag">评分{{data.sorce}}</text>
						</view>
						<view style="margin-top:10rpx">
						  ￥{{data.dprice}}
						</view>
						<view style="display:flex;margin-top:10rpx">
							<view style="width:130rpx;text-align: center;">
								<u-tag type="error" v-if="data.state==1" text="已审核"></u-tag>
								<u-tag type="warning" v-if="data.state==0" text="待审核"></u-tag>
							</view>
							<view style="width:100rpx;text-align: center;margin-left:20rpx">
								<u-tag type="success"  v-if="data.state==1" text="销售"></u-tag>
								<u-tag type="warning" v-if="data.state==0" text="停售"></u-tag>
							</view>
						</view>
					</u-col>
					<u-col span="1" @click="goEdit(data.dishesId)">
						<u-icon name="edit-pen-fill" size="20"></u-icon>
					</u-col>
				  </u-row>
				</view>
			  </block>
		</view>
	</view>
</template>

<script>
	import Config from '@/util/index.js'
	import {
	 getGoodsByRant
	} from '@/api/goods'
	export default {
		data() {
			return {
				imgpath: "",
				pagenum: 0,
				pagesize: 10,
				rcode:'',
				mid:'',
				deptId:'',
				shopName:'',
				noNotice: false,
				shopState: false,
				list:[],
				moreData:false,
				noData:false,
				noActive:false,
				uploadFilePath:''
			}
		},
		onLoad(options) {
			this.mid = options.shopid
			this.shopName = options.shopname
			this.deptId = options.rcode
			this.imgpath = Config.get('apiUrl')
			this.getSGoodsList()
		},
		onShow() {
			this.uploadFilePath = Config.get('apiUrl')
		},
		methods: {
			addGoods(){
				uni.navigateTo({
					url:`edit?shopid=${this.mid}&rcode=${this.deptId}`
				})
			},
			goEdit(id){
				uni.navigateTo({
					url: `edit?goid=${id}`
				})
			},
			backPage(){
				uni.navigateBack()
				// uni.switchTab({
				// 	url: "pages/shop/manage/index"
				// })	
			},
			getSGoodsList(){
			  if(this.moreData){
			    return false
			  }else{
			      this.pagenum++
			  }
			  uni.showLoading({
			    title: '加载中...',
			  })
			  let params = {
			      shopId:this.mid,
					deptId:this.deptId,
			      pageNum:this.pagenum,
			      pageSize:this.pagesize
			  }
			  let _this = this
				getGoodsByRant(params).catch(res => {
					console.log("ress",res)
					 if(res.data.rows.length > 0){
					   const newList = res.data.rows
					   uni.hideLoading()
					   const total = parseInt(res.data.total)
					   if(_this.list.length < total){
							_this.list = [..._this.list,...newList]
						   _this.total =total
					   }else{
						   _this.moreData = true
					   }
					   
					 }else{
					   uni.hideLoading()
					   if(_this.pagenum==0){
						   _this.noData = true
					   }
						_this.moreData = true
					 }
				})
			},
			goGoodsDe(data){
			  uni.navigateTo({
			    url: '../goods/detail?goods='+encodeURIComponent(JSON.stringify(data))
			  })
			},
			onReachBottom(){
				this.getSGoodsList()
			},
			onShopState(e) {
				this.shopState = e
				let state = this.shopState ? '1' : '0'
				this.shopStateSwitch(state)
			},
			
			shopStateSwitch(value) {
				let params = {
					mid: uni.getStorageSync('loginInfo').mid,
					openflag: value
				}
				Api.shopSwitch(params).then(res => {
					if (res.retCode == 0) {
						if (value == 1) {
							uni.showToast({
								title: '已开通营业',
								icon: 'none',
								duration: 2000
							});
						} else {
							uni.showToast({
								title: '已关闭营业',
								icon: 'none',
								duration: 2000
							});
						}
					}
				})
			},
			orderStateSwitch(value) {
				let params = {
					mid: uni.getStorageSync('loginInfo').mid,
					orderflag: value
				}
				Api.changeOrder(params).then(res => {
					if (res.retCode == 0) {
						uni.showToast({
							title: '已开通下单',
							icon: 'none',
							duration: 2000
						});
					} else {
						uni.showToast({
							title: '关闭下单',
							icon: 'none',
							duration: 2000
						});
					}
				})
			},
			getStoreInfo() {
				let _this = this
				uni.showLoading({
					title: '加载中...'
				})
				uni.getStorage({
					key: 'userifo',
					success: function (res) {
						console.log("000",res)
						if(res.data){
							let params = {
								userName:JSON.parse(res.data).userName
							}
							console.log("111",params)
							Api.getShopIfoBytel(params).then(res => {
								_this.shopIfo = res.data.rows
								// _this.getNoticeInfo()
								uni.hideLoading()
							})
						}
					}
				});
			},
			goEditstore() {
				uni.navigateTo({
					url: 'manage/edit?sifo=' + JSON.stringify(this.storeInfo),
				})
			},
			async delNotice(pid) {
				let params = {
					pid: pid
				}
				let _this = this
				const res = await showModel({
					content: '你确定要删除该公告吗？'
				});
				//在模态框中点击确认，删除购物车中的该商品数据
				if (res.confirm) {
					Api.deteleNotice(params).then(res => {
						if (res.retCode == 0) {
							showToast({
								title: "删除成功"
							})
							_this.getNoticeInfo()
						} else {
							console.log(res.info)
						}
					})
				} else {
					//取消删除
					//弹出提示取消删除
					await showToast({
						title: "取消删除"
					})
				}
			},
			goActivePage() {
				uni.navigateTo({
					url: 'manage/active?rcode=' + this.storeInfo.rcode,
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.u-page {
		padding: 0;
	}

	.u-demo-block__title {
		padding: 10px 0 2px 15px;
	}

	.swipe-action {
		&__content {
			padding: 25rpx 0;

			&__text {
				font-size: 15px;
				color: $u-main-color;
				padding-left: 30rpx;
			}
		}
	}

	/* pages/manage/manageorder.wxss */
	.warp {
		width: 100%;
		margin: 10rpx auto;
		background: #f5f5f5
	}
	.mdol {
		height: auto;
	}
	.shop{padding:20px;background:#fff;margin-top:10px}
	.dplogo {
		width: 180rpx;
		height: 180rpx;
	}

	.dplb {
		display: flex;
		text-align: center;
		margin: 30rpx auto;
	}

	.dpcss {
		width: 100%;
		height: 150rpx;
		line-height: 150rpx;
		flex: 1;
		margin: 0rpx 20rpx;
		border-radius: 10px;
	}

	.u-swipe-cell__left,
	.u-swipe-cell__right {
		display: inline-block;
		width: 130rpx;
		height: 70rpx;
		font-size: 1rem;
		line-height: 90rpx;
		color: #fff;
		text-align: center;
		background-color: #F66B71;
	}

	.glcs {
		width: 100%;
		height: auto;
		background: #ffffff;
		padding-top: 10rpx;
		margin-top: 10rpx
	}



	.dpxx {
		width: 100%;
		text-align: center;
		margin: 20rpx auto;
		line-height: 60rpx;
		font-size: 1rem
	}

	.dpkg {
		display: flex;
		align-items: left;
		justify-content: left;
		height: 70rpx;
		line-height: 70rpx;
		text-align: left;
	}

	.havegg {
		display: flex;
		width: 100%;
		height: 70rpx;
		line-height: 70rpx;
		border-bottom: 1px solid #f5f5f5;
	}

	.dpgg {
		height: auto;
		background: #ffffff;
		margin-top: 10rpx;
		background: #ffffff;
		padding: 0rpx 20rpx;
		line-height: 60rpx;
	}
</style>
